package solution;

import java.util.ArrayList;
import java.util.List;

class Solution {
    public static void setZeroes(int[][] matrix) {
        int n = matrix.length;
        int m = matrix[0].length;

        List<int[]> list = new ArrayList<>(); //存放元素为 0 的下标
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (matrix[i][j] == 0) {
                    list.add(new int[]{i, j});
                }
            }
        }

        for (int[] arr : list) {
            //将一行变为 0
            for (int j = 0; j < m; j++) {
                matrix[arr[0]][j] = 0;
            }

            //将一列变为 0
            for (int i = 0; i < n; i++) {
                matrix[i][arr[1]] = 0;
            }
        }
    }

    public static void main(String[] args) {
        setZeroes(new int[][]{{0,1,2,0}, {3,4,5,2}, {1,3,1,5}});
    }
}